package com.pattern.command.tenant;

import com.pattern.command.frame.Command;
import com.pattern.command.third.Service1;

public class Command1 implements Command {
    private String userName;   // inParam
    private int userId;        // outParam

    public int getUserId() {
        return userId;
    }

    public Command1(String userName) {
        this.userName = userName;
    }

    @Override
    public boolean execute() {
        // 此处调用 RPC1  用try catch包裹
        int id = Service1.createUser(userName);
        if(id<0) {
            return false;
        }
        userId = id;
        return true;
    }

    @Override
    public boolean undo() {
        // 此处调用 RPC1 接口的逆向接口  rRPC1，其参数从inParam和outParam取得
        return Service1.deleteUser(userId);
    }
}
